﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

/// <summary>
/// Summary description for CartInfoViewer
/// </summary>
public class CartInfoViewer
{
    public static string Viewer(Order order)
    {
        StringBuilder ret = new StringBuilder("NONE OF PRODUCT");
        if (order != null)
        {
            if (order.OrderDetails != null && order.OrderDetails.Count > 0)
            {
                ret = new StringBuilder();
                ret.Append("<table align='center' class='cart_table' cellspacing='0'>");
                ret.Append(_formatHeader);
                int stt = 0;
                foreach (OrderDetail item in order.OrderDetails)
                {
                    stt++;
                    int totalItemPrice = item.TotalPrice();
                    ret.AppendFormat(_formatBody, stt.ToString(), item.Product.ProductName, item.Quantity, Formatter.PriceVietNamese(item.PriceAtBuy), Formatter.PriceVietNamese(totalItemPrice), item.ProductId);
                }
                ret.AppendFormat(_formatFooter, order.TotalPrice());
                ret.Append("</table>");
            }
        }
        return ret.ToString();
    }

    
    static string _formatBody = @"<tr class='tetx_grey_normal'>
    <td class='table_row'>
        {0}
    </td>
    <td class='table_row colName'>
        <a href='ProductDetail.aspx?pi={5}'>{1}</a>
    </td>
    <td class='table_row'>
        <input type='text' class='textbox' id='{5}txtQuantity' pi='{5}' style='text-align:center' value='{2}' />
    </td>
    <td class='table_row colPrice'>
        {3}
    </td>
    <td class='table_row colPrice'>
        {4}
    </td>
    <td width='32' class='table_row1'>
        <a href='javascript:Five.Cart.Remove({5});'><img src='../Img/Layout/edit_btn.gif' /></a>
    </td>
</tr>";
    static string _formatFooter = @"<tr class='tetx_grey_normal'>
                    <td class='table_row_last'>
                    </td>
                    <td class='table_row_last'>
                    </td>
                    <td class='table_row_last'>
                    </td>
                    <td class='table_row_last'>
                        Tổng tiền
                    </td>
                    <td class='table_row_last price_pink'>
                        {0}
                    </td>
                    <td width='32' class=''>
                    </td>
                </tr>";
    static string _formatHeader = @"<tr class='productname_green'>
    <td width='40px' class='table_row1'>
        STT
    </td>
    <td width='230px' class='table_row1 colName'>
        Sản phẩm
    </td>
    <td width='100' class='table_row1'>
        Số lượng
    </td>
    <td width='100' class='table_row1'>
        Ðơn giá
    </td>
    <td class='table_row1'>
        Thành tiền
    </td>
    <td width='32' class='table_row1'>
    </td>
</tr>";
}

